﻿/*
.NET快速开发整合框架（RDIFramework.NET），基于.NET的快速信息化系统开发、整合框架，给用户和开发者最佳的.Net框架部署方案。

博客：[CSDN]http://blog.csdn.net/chinahuyong	
[CNBLOGS]http://www.cnblogs.com/huyong 

交流QQ：406590790 
QQ群：16653241
微博：http://t.qq.com/yonghu86
邮箱：406590790@qq.com
*************************************************************************************
* RDIFramework.NET框架“表（字段）综合管理”业务界面逻辑
*
* 主要完成员工的增加、修改、删除、移动、导出等。
* 修改记录：
*   1. 2013-08-22 EricHu 新增本业务逻辑的编写。
*/

var actionUrl = 'handler/TableFieldAdminHandler.ashx';
//var formUrl = "Modules/html/StaffForm.htm";

$(function () {
    var size = { width: $(window).width(), height: $(window).height() };
    mylayout.init(size);
    $(window).resize(function () {
        size = { width: $(window).width(), height: $(window).height() };
        mylayout.resize(size);
    });

    tableList.init();
    autoResize({ dataGrid: '#tableFieldGird', gridType: 'datagrid', callback: mygrid.databind, height: 36, width: 230 });
    $(window).resize(function () {
        size = { width: $(window).width(), height: $(window).height() };
        mylayout.resize(size);
    });
});

var mylayout = {
    init: function (size) {
        $('#layout').width(size.width - 4).height(size.height - 4).layout();
        var center = $('#layout').layout('panel', 'center');
        center.panel({
            onResize: function (w, h) {
                $('#tableFieldGird').datagrid('resize', { width: w - 6, height: h - 36 });
            }
        });
    },
    resize: function (size) {
        mylayout.init(size);
        $('#layout').layout('resize');
    }
};

var tableList = {
    init: function () {
        $('#tbData').datagrid({
            noheader: true,
            nowrap: false,
            rownumbers: true,
            resizable: true,
            singleSelect: true,
            collapsible: false,
            url: actionUrl + '?action=GetTableNameAndCode',
            columns: [[
                 { title: '表名', field: 'TableName', width: 260 },
                 { title: 'TableCode', field: 'TableCode', hidden: true }
            ]],
            onLoadSuccess: function (data) {
            },
            onClickRow: function (rowIndex, rowData) {
                $('#tableFieldGird').datagrid({
                    url: actionUrl + '?action=GetDTByTable&tableCode=' + rowData.TableCode                    
                });
            }
        });
    },
    selectRow: function () {
        return $('#tbData').datagrid('getSelected');
    }
};

var mygrid = {
    databind: function (size) {
        $('#tableFieldGird').datagrid({
            title: "表字段明细",
            loadMsg: "正在加载表字段明细，请稍等...",
            width: size.width,
            height: size.height,
            idField: 'Id',
            singleSelect: true,
            striped: true,
            rownumbers: true,
            columns: [[
                    { title: 'Id', field: 'Id', hidden: true },
                    { title: '英文名称', field: 'ColumnCode', width: 130 },
                    { title: '数据类型', field: 'DataType', width: 70 },
                    { title: '中文名称', field: 'ColumnName', width: 130 },
                    { title: '公开', field: 'IsPublic', align: "center", width: 50, formatter: imgcheckbox },
                    { title: '访问权限', field: 'ColumnAccess', align: "center", width: 50, formatter: imgcheckbox },
                    { title: '编辑权限', field: 'ColumnEdit', align: "center", width: 50, formatter: imgcheckbox },
                    { title: '拒绝访问', field: 'ColumnDeney', align: "center", width: 50, formatter: imgcheckbox },
                    { title: '启用约束', field: 'UseConstraint', align: "center", width: 50, formatter: imgcheckbox },
                    { title: '查询列', field: 'IsSearchColumn', align: "center", width: 50, formatter: imgcheckbox },
                    { title: '展示列', field: 'IsExhibitColumn', align: "center", width: 50, formatter: imgcheckbox },
                    { title: '允许编辑', field: 'AllowEdit', align: "center", width: 50, formatter: imgcheckbox },
                    { title: '允许删除', field: 'AllowDelete', align: "center", width: 50, formatter: imgcheckbox },
                    { title: '可用', field: 'Enabled', align: "center", width: 50, formatter: imgcheckbox },
                    { title: '有效', field: 'Enabled', width: 50, align: 'center', formatter: imgcheckbox },
                    { title: '描述', field: 'Description', width: 260 }
                ]]
        });
    },
    reload: function () {
        $('#tableFieldGird').datagrid('reload');
    },
    selectRow: function () {
        return $('#tableFieldGird').datagrid('getSelected');
    }
};

var imgcheckbox = function (cellvalue, options, rowObject) {
    return cellvalue ? '<img src="/css/icon/ok.png" alt="正常" title="正常" />' : '<img src="/css/icon/stop.png" alt="禁用" title="禁用" />';
};